package keshe.view;

import keshe.ACCOUNT;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AccountJPanel extends JPanel implements ActionListener {//个人账户界面

    private JLabel Username=new JLabel();
    private JLabel Money=new JLabel();
    private JLabel Idcard=new JLabel();
    private JLabel bankId=new JLabel();
    private JPanel sex=new JPanel(new GridLayout(1,3));
    public JRadioButton jbutton[]=new JRadioButton[2];
    private ButtonGroup Sex=new ButtonGroup();
    public AccountJPanel(ACCOUNT account){
        //设置带标题的边框
        this.setBorder(new TitledBorder("个人账户(需刷新个人信息)"));
        this.setLayout(new GridLayout(6,1));
        //添加个人信息
        Username.setText("用户名："+account.getUserName());
        bankId.setText("银行卡号："+account.getBankCardId());
        Idcard.setText("身份证号："+account.getIDcard().substring(0,6)+"********"+account.getIDcard().substring(14,16)+"**");
        Money.setText("剩余金额："+account.getMoney());
        this.add(Username);
        this.add(bankId);
        this.add(Money);
        this.add(Idcard);

        //添加性别单选按钮
        jbutton[0]=new JRadioButton("男");
        jbutton[1]=new JRadioButton("女");
        Sex.add(jbutton[0]);
        Sex.add(jbutton[1]);
        if(account.getSex().equals("男")){
            jbutton[0].setSelected(true);
        }else {
            jbutton[1].setSelected(true);
        }
        JLabel sextitl=new JLabel("性别");
        sex.add(sextitl);
        sex.add(jbutton[0]);
        sex.add(jbutton[1]);
        this.add(sex);

        //添加查看明细按钮
        JButton Info=new JButton("账户明细");
        Info.addActionListener(e->{
            new AccountInfoJFrame(account);
        });
        JPanel cmd=new JPanel(new GridLayout(2,1));
        this.add(cmd);
        cmd.add(Info);
        //添加修改密码按钮
        JButton change=new JButton("修改密码");
        change.addActionListener(e->{
            new ChangePasswordJFrame(account);
        });
        cmd.add(change);

        this.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {

    }
}
